package com.gxa.controller.ly.systemManagement;

import com.github.pagehelper.PageInfo;
import com.gxa.common.R;
import com.gxa.entity.SysTypeManagement;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Api(value = "类型管理",tags = "类型管理接口API")
@Controller
@RequiresRoles(value = {"超级管理员","院长"},logical = Logical.OR)
@RequestMapping("/systemManagement/typeManagement")
public class TypeManagementController {



    @RequestMapping(value = "/findTypeList",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查找类型接口",notes = "查找类型",httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页" ,required = true),
            @ApiImplicitParam(name = "pageSize",value = "页数" ,required = true)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R<SysTypeManagement> findTypeList(Integer currentPage,Integer pageSize){
        R r = new R<>();
        if (currentPage != null && pageSize != null) {
            SysTypeManagement sysTypeManagement = new SysTypeManagement();
            sysTypeManagement.setId(1);
            sysTypeManagement.setListName("address_list");
            sysTypeManagement.setDesc("类型描述");
            sysTypeManagement.setDisplay("类型显示");
            sysTypeManagement.setValue(1);

            SysTypeManagement sysTypeManagement1 = new SysTypeManagement();
            sysTypeManagement1.setId(2);
            sysTypeManagement1.setListName("address_list1");
            sysTypeManagement1.setDesc("类型描述");
            sysTypeManagement1.setDisplay("类型显示");
            sysTypeManagement1.setValue(2);

            List<SysTypeManagement> list = new ArrayList<>();

            list.add(sysTypeManagement);
            list.add(sysTypeManagement1);
            PageInfo<SysTypeManagement> pageInfo = new PageInfo<>(list);
            r.setMsg("success");
            r.setData(pageInfo);
            r.setCode(200);

        }else {
            r.setMsg("参数错误");
            r.setCode(400);
        }
        return r;
    }

    /**
     * 添加类型接口
     * @param sysTypeManagement 类型对象
     * @return 状态码消息
     */
    @RequestMapping(value = "/addType",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "添加类型接口",notes = "添加类型",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R addType(@RequestBody @ApiParam(name = "添加类型接口" ,value = "各种类型添加在这") SysTypeManagement sysTypeManagement){
        R r = new R<>();

        if (sysTypeManagement != null) {
            return  R.ok();
        }else {
            r.setCode(400);
            r.setMsg("没传输数据");
        }
        return r;
    }

    /**
     * 删除类型接口
     * @param id 类型id
     * @return 状态码
     */
    @RequestMapping(value = "/delType",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "删除类型接口",notes = "删除类型",httpMethod = "POST", response = R.class)
    @ApiImplicitParam(name = "id",value = "类型id",required = true)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R delType(Integer id){
        R r = new R<>();

        if (id != null) {
            return R.ok();
        }else {
            r.setCode(400);
            r.setMsg("参数错误");
        }

        return r;
    }


    /**
     * 更新类型接口
     * @param sysTypeManagement 类型对象
     * @return 返回状态码信息
     */
    @RequestMapping(value = "/updateType",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "更新类型接口",notes = "更新类型",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=400,message="参数错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R<SysTypeManagement> updateType(@RequestBody @ApiParam(name = "更新类型接口" ,value = "各种类型更新") SysTypeManagement sysTypeManagement){

        R r = new R<>();

        if (sysTypeManagement != null) {
            return R.ok();
        }else {
            r.setCode(400);
            r.setMsg("没传输数据");
        }
        return r;
    }


}
